package com.un.web.topic.controller;

import cn.hutool.db.Page;
import com.github.pagehelper.PageInfo;
import com.un.core.common.R;
import com.un.web.topic.domian.entity.TopicJava;
import com.un.web.topic.domian.entity.TopicType;
import com.un.web.topic.service.TopicJavaService;
import com.un.web.topic.service.impl.TopicJavaServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author xingjian
 * @Date 2023-01-31
 **/

@RestController
@RequestMapping("/topic_java")
public class TopicJavaController {

    @Autowired
    private TopicJavaService topicJavaService;


    @GetMapping("selectOne")
    public R selectOne(Integer id) {
        return R.success(topicJavaService.getById(id));
    }

    @GetMapping("listPage")
    public R getAll(Page page){
        PageInfo<TopicJava> list = topicJavaService.selectAllByPage(page);
        return R.success(list);
    }

    @PostMapping("save")
    public R save(@RequestBody TopicJava topicJava){
        topicJavaService.saveOrUpdate(topicJava);
        return R.success();
    }

    @DeleteMapping("delete/{id}")
    public R delete(@PathVariable Integer id){
        topicJavaService.removeById(id);
        return R.success();
    }

}
